import { createApp,createVNode ,render} from 'vue'
// import './style.css'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import loadingBar from './components/loadingBar.vue'

const Vnode = createVNode(loadingBar)
// console.log(Vnode)
render(Vnode,document.body)

const app=createApp(App)
app.use(router)
app.use(ElementPlus)

const whileList = ['/']

router.beforeEach((to,from,next)=>{
    console.log(to)
    document.title = to.meta.title // 报错去路由界面声明类型
    Vnode.component?.exposed?.startLoading()
    if(whileList.includes(to.path) || localStorage.getItem('token')){
        next()
    }else{
        next('/')
    }
})

router.afterEach((to,from)=>{
    Vnode.component?.exposed?.endLoading()

})

app.mount('#app')
